/***************************************************************************\
 * The Mattise Kernel														*
 * Copyright 2007 Matthew Iselin											*
 * Licensed under the GPL													*
 *																			*
 * pm.h																		*
 *																			*
 * Page management - courtesy of Kevin McGuire								*
 *																			*
\***************************************************************************/

// note from pcmattman: I've gone through this file neatening it up to be more readable
// and to match the format of the rest of the Mattise includes

// Pragmas
#ifndef PM_H
#define PM_H
#include <stdint.h>

// Constants
#define PM_FLUSH_ONLYVALID 0x800			// only use with pm_set; only operates on valid pages in the specified range.
#define PM_FLAG_MASK 0xFF				// allows extra information to be tagged to entires that does not affect us.
#define PM_VALID 0x001					// if page exists in system; the state might be otherwise.
#define PM_USED 0x002					// the state of this page is used!
#define PM_LEGACY 0x004					// legacy memory allocated by DMA and VM86 applications(before virtual memory).
#define PM_INTERNAL 0x008

extern unsigned long *pm_dir;

// Prototypes

uintptr_t pm_alloc5(unsigned long from, unsigned long to, unsigned long count, unsigned long mask, unsigned long fortag, unsigned long totag);

// allocate specified number of pages that match the mask and fortag, then add tag to pages on success.
uintptr_t pm_alloc4(unsigned long mask, unsigned fortag, unsigned totag, unsigned long count);

// allocate specified number of pages starting at 'from' and ending at 'to'.
uintptr_t pm_alloc3(unsigned long from, unsigned long to, unsigned long count);

// allocate specified number of pages.
uintptr_t pm_alloc2(unsigned long count);

// allocate one page
uintptr_t pm_alloc();

// free specified number of contigious pages starting at page.
int pm_free2(unsigned long page, unsigned long count);

// free one page.
int pm_free(unsigned long page);

// internal control
void pm_set(unsigned long page, unsigned long count, unsigned long code);
void pm_set_flush();

// common initialization
void pm_init(unsigned long page, unsigned long count);

// specialized initialization
typedef struct{
   unsigned long   size;
   unsigned long   base_low;
   unsigned long   base_high;
   unsigned long   size_low;
   unsigned long   size_high;
   unsigned long   type;
}pm_tmbmm;
int pm_init_with_grub_mmap(unsigned long mmap_addr, unsigned long mmap_length);
#endif

